from common.base import *
from common.browser import *


class Receiving_address(Base):
    # 输入用户名
    def input_username(self, username):
        self.send_keys((By.NAME, 'username'), username)

    # 密码输入框
    def input_password(self, password):
        self.send_keys((By.NAME, 'password'), password)

    # 点击保存本次登录信息
    def button(self):
        self.click((By.XPATH, 'remember'))

    # 点击按钮进行登录
    def btn_login(self):
        self.click((By.NAME, 'submit'))

    # 点击进入收货地址
    def get_into(self):
        self.driver.find_element(By.PARTIAL_LINK_TEXT, '用户中心').click()
        self.driver.find_element(By.PARTIAL_LINK_TEXT, '收货地址').click()

    # 选择省
    def province(self, location, value):
        self.select((By.ID, location), value)

    # 选择市
    def city(self, location, value):
        self.select((By.ID, location), value)

    # 选择区
    def area(self, location, value):
        self.select((By.ID, location), value)

    # 输入名字
    def ipt_name(self, location, value):
        self.send_keys((By.ID, location), value)

    # 清除名字
    def clear_name(self):
        self.clear_text((By.ID, 'consignee_0'))

    # 输入地址
    def ipt_address(self, location, value):
        self.send_keys((By.ID, location), value)

    # 填入号码
    def ipt_number(self, location, value):
        self.send_keys((By.ID, location), value)

    # 点击按钮新增地址
    def btn(self):
        self.click((By.CLASS_NAME, 'bnt_blue_2'))

    # 点击确认修改地址
    def btn_modify(self):
        self.click((By.CLASS_NAME, 'bnt_blue_1'))

    # 点击收货地址删除
    def cut(self):
        self.click((By.CLASS_NAME, 'bnt_blue'))
        self.switch_to_alert()  # 捕捉弹框

    # 封装一个返回收件人value值
    def addressee(self):
        addressee = self.find_element((By.ID, 'consignee_0')).get_attribute('value')
        if addressee == '':
            return None
        else:
            return addressee

    def addressee_name(self):
        return self.get_text((By.ID, 'consignee_0'))